<template>
  <div class="overlay">
    <van-overlay :show="showoff">
      <div class="wrapper" @click.stop>
        <div class="block">
          <div class="closebox">
            <span @click="closeFn">
              <svg-icon iconClass="close"></svg-icon>
            </span>
            <span>请输入支付密码</span>
            <span></span>
          </div>
          <div class="payprice">
            <p class="payjine">支付金额</p>
            <p class="jine">
              <b>￥{{this.$route.query.value}}</b>
            </p>
          </div>
          <van-password-input
            :value="value"
            info="密码为 6 位数字"
            :error-info="errorInfo"
            :focused="showKeyboard"
            @focus="showKeyboard  = true"
          />
          <van-number-keyboard v-model="value" :show="showKeyboard" @blur="showKeyboard = true" />
        </div>
      </div>
    </van-overlay>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      value: "",
      errorInfo: "",
      showKeyboard: true
    };
  },
  props: {
    showoff: Boolean,
    radio: String
  },
  created() {},
  methods: {
    closeFn() {
      this.$emit("close", !this.showoff);
    }
  },
  created() {
    console.log(this.radio);
  },
  watch: {
    value(value) {
      if (value.length === 6 && value !== "123456") {
        this.errorInfo = "密码错误";
      } else if (value.length === 6 && value == "123456") {
        this.errorInfo = "密码正确";
        this.$router.push({
          path: "/payok",
          query: {
            value: this.$route.query.value,
            radio: this.radio
          }
        });
      } else {
        this.errorInfo = "";
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@css/style.scss";

.overlay {
  width: 100%;
  height: 100%;
  .wrapper {
    display: flex;
    justify-content: center;
    height: 100%;
  }

  .block {
    width: px2rem(311);
    height: px2rem(344);
    margin-top: px2rem(20);
    background-color: #fff;
    border-radius: px2rem(25);
    .closebox {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 px2rem(10);
      height: px2rem(58);
      font-size: px2rem(20);
      border-bottom: 1px solid blueviolet;
    }
    .payprice {
      text-align: center;
      .payjine {
        font-size: px2rem(24);
        padding: px2rem(25) 0;
      }
      .jine {
        padding: px2rem(20) 0 px2rem(50) 0;
      }
    }
  }
}
</style>